package com.micro.school.order.controller;

import com.micro.school.common.core.context.SecurityContextHolder;
import com.micro.school.common.core.web.controller.BaseController;
import com.micro.school.common.core.web.domain.AjaxResult;
import com.micro.school.common.core.web.page.TableDataInfo;
import com.micro.school.order.entity.PayPrepaymentProject;
import com.micro.school.order.service.PayPrepaymentProjectService;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * 预缴费项目管理接口
 */
@RequestMapping("/payPrepayment")
@RestController
public class PayPrepaymentProjectController extends BaseController {

    @Resource
    private PayPrepaymentProjectService payPrepaymentProjectService;

    /**
     * 预缴费项目管理列表查询
     *
     * @param payPrepaymentProject 预缴费项目查询参数
     * @return 预缴费项目列表
     */
    @GetMapping("/queryPrepaymentList")
    public TableDataInfo queryPrepaymentList(PayPrepaymentProject payPrepaymentProject) {
        startPage();
        payPrepaymentProject.setTenantId(SecurityContextHolder.getUserTenantId());
        List<PayPrepaymentProject> payPrepaymentProjects = payPrepaymentProjectService.queryList(payPrepaymentProject);
        return getDataTable(payPrepaymentProjects);
    }

    /**
     * 预缴费项目管理列表查询
     *
     * @param payPrepaymentProject 预缴费项目查询参数
     * @return 预缴费项目列表
     */
    @GetMapping("/queryAllPrepayment")
    public AjaxResult queryAllPrepayment() {
        PayPrepaymentProject payPrepaymentProject = new PayPrepaymentProject();
        payPrepaymentProject.setTenantId(SecurityContextHolder.getUserTenantId());
        payPrepaymentProject.setDeleteFlag("0");
        List<PayPrepaymentProject> payPrepaymentProjects = payPrepaymentProjectService.queryList(payPrepaymentProject);
        return success(payPrepaymentProjects);
    }


    /**
     * 预缴费项目添加
     *
     * @param payPrepaymentProject 预缴费项目信息
     * @return 添加结果
     */
    @PostMapping("/addPrepayment")
    public AjaxResult addPrepayment(@RequestBody PayPrepaymentProject payPrepaymentProject) {
        payPrepaymentProject.setTenantId(SecurityContextHolder.getUserTenantId());
        payPrepaymentProject.setCreateTime(new Date());
        payPrepaymentProject.setUpdateTime(new Date());
        payPrepaymentProject.setCreateBy(SecurityContextHolder.getUserName());
        payPrepaymentProject.setUpdateBy(SecurityContextHolder.getUserName());
        payPrepaymentProject.setDeleteFlag("0");
        payPrepaymentProjectService.insert(payPrepaymentProject);
        return success("新增成功！");
    }

    /**
     * 预缴费项目单个查询
     *
     * @param id 预缴费项目ID
     * @return 预缴费项目信息
     */
    @GetMapping("/getPrepayment")
    public AjaxResult getPrepayment(Integer id) {
        PayPrepaymentProject payPrepaymentProject = payPrepaymentProjectService.queryById(id);
        return success(payPrepaymentProject);
    }


    /**
     * 预缴费项目修改
     *
     * @param payPrepaymentProject 预缴费项目信息
     * @return 修改结果
     */
    @PostMapping("/updatePrepayment")
    public AjaxResult updatePrepayment(@RequestBody PayPrepaymentProject payPrepaymentProject) {
        payPrepaymentProject.setTenantId(SecurityContextHolder.getUserTenantId());
        payPrepaymentProject.setUpdateTime(new Date());
        payPrepaymentProject.setUpdateBy(SecurityContextHolder.getUserName());
        payPrepaymentProjectService.update(payPrepaymentProject);
        return success("修改成功！");
    }


}